const textEl = document.getElementById('text')
const inputEl = document.getElementById('speed')

const text = 'We Love Programming!'

const time = 1000
let idx = 1
let speed = time / inputEl.value

writeText()

function writeText() {
	let content = text.slice(0, idx)
	textEl.innerText = content
	
	idx++
	
	if (idx > text.length) {
		idx = 1
	}
	
	setTimeout(writeText, speed)
} 

inputEl.addEventListener('input', (e) => speed = 1000 / e.target.value)